home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_client_tracking.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  6.9 KB  |  311 lines

  1. unit ntc_client_tracking;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     StdCtrls,
  36.     Buttons,
  37.     ExtCtrls,
  38.     inifiles,
  39.  
  40.     ntc_client_form;
  41.  
  42. const
  43.     default_deviation=0.1;
  44.     default_rate=60;
  45.     default_lunar_rate=57.9;
  46.  
  47. type
  48.     Tscope_tracking = class(tform)
  49.         tracking_panel: TPanel;
  50.         change_tracking_group: TGroupBox;
  51.         increase_tracking_button: TBitBtn;
  52.         preset_defaults_group: TGroupBox;
  53.         lunar_tracking_button: TBitBtn;
  54.         default_tracking_button: TBitBtn;
  55.         lunar_tracking_label: TLabel;
  56.         default_tracking_label: TLabel;
  57.         decrease_tracking_button: TBitBtn;
  58.         tracking_edit: TEdit;
  59.  
  60.         { form handling }
  61.         procedure FormCreate(
  62.             Sender: TObject);
  63.  
  64.         procedure form_close_query(
  65.                     Sender: TObject;
  66.             var CanClose: Boolean);
  67.  
  68.         { configuration }
  69.         procedure save_settings;
  70.  
  71.         procedure load_settings;
  72.  
  73.         procedure flip_buttons(
  74.             toggle:boolean);
  75.  
  76.         { events }
  77.         procedure FormShow(
  78.             Sender:TObject);
  79.  
  80.         procedure adjust;
  81.  
  82.         procedure check_activate(
  83.             Sender: TObject);
  84.  
  85.         procedure decrease_tracking_buttonClick(
  86.             Sender: TObject);
  87.  
  88.         procedure increase_tracking_buttonClick(
  89.             Sender: TObject);
  90.  
  91.         procedure lunar_tracking_buttonClick(
  92.             Sender: TObject);
  93.  
  94.         procedure default_tracking_buttonClick(
  95.             Sender: TObject);
  96.  
  97.         procedure tracking_editChange(
  98.             Sender: TObject);
  99.  
  100.     private
  101.         { Private declarations }
  102.         default_tracking_rate,
  103.         default_lunar_tracking_rate:double;
  104.         tracking_rate,
  105.         lunar_tracking_rate:double;
  106.         lunar_tracking:boolean;
  107.     public
  108.         { Public declarations }
  109.         can_track:boolean;
  110.         tracks_by:double;
  111.         { configuration }
  112.         dimensions:dimensions_record;
  113.  
  114.         { events }
  115.         procedure check_visible_and_show_hide(
  116.             sender:tobject);
  117.             
  118.         procedure hide_form;
  119.         procedure show_form;
  120.     end;
  121.  
  122. var
  123.     scope_tracking:Tscope_tracking;
  124.  
  125. implementation
  126.  
  127. uses
  128.     ntc_client_network;
  129.  
  130. {$R *.dfm}
  131.  
  132.     { -------------
  133.         form handling
  134.         ------------- }
  135.  
  136. procedure Tscope_tracking.FormCreate(Sender: TObject);
  137. begin
  138.     default_tracking_rate:=default_rate;
  139.     tracking_rate:=default_tracking_rate;
  140.     default_lunar_tracking_rate:=default_lunar_rate;
  141.     lunar_tracking_rate:=default_lunar_tracking_rate;
  142.     tracking_edit.text:=floattostr(tracking_rate);
  143.     lunar_tracking:=false;
  144.     can_track:=false;
  145.     tracks_by:=default_deviation;
  146.     flip_buttons(false);
  147.     load_settings;
  148. end;
  149.  
  150. procedure tscope_tracking.form_close_query(
  151.             Sender: TObject;
  152.     var CanClose: Boolean);
  153. begin
  154.     canclose:=false;
  155.     visible:=false;
  156.     with dimensions do
  157.         begin
  158.             form_top:=top;
  159.             form_left:=left;
  160.         end;
  161. end;
  162.  
  163.     { ---------
  164.         utilities
  165.         --------- }
  166.  
  167. procedure Tscope_tracking.flip_buttons(
  168.     toggle:boolean);
  169. begin
  170.     change_tracking_group.enabled:=toggle;
  171.     preset_defaults_group.enabled:=toggle;
  172. end;
  173.  
  174.     { -------------
  175.         configuration
  176.         ------------- }
  177.  
  178. procedure tscope_tracking.load_settings;
  179. begin
  180.     ini_file:=tinifile.create(application_path+'client.ini');
  181.     with ini_file do
  182.         begin
  183.             tracks_by:=ReadFloat('tracking','tracks_by',default_deviation);
  184.             default_tracking_rate:=ReadFloat(
  185.                 'tracking','default_tracking_rate',default_rate);
  186.             default_lunar_tracking_rate:=readfloat(
  187.                 'tracking','default_lunar_tracking_rate',default_lunar_rate);
  188.             { form }
  189.             scope.get_dimensions(scope_tracking,@dimensions,'tracking',ini_file);
  190.             left:=dimensions.form_left;
  191.             top:=dimensions.form_top;
  192.             visible:=readbool('tracking','visible',false);
  193.         end;
  194.     ini_file.free;
  195. end;
  196.  
  197. procedure tscope_tracking.save_settings;
  198. begin
  199.     with ini_file do
  200.         begin
  201.             writefloat('tracking','default_tracking_rate',default_tracking_rate);
  202.             writefloat(
  203.                 'tracking','default_lunar_tracking_rate',default_lunar_tracking_rate);
  204.             writefloat('tracking','tracks_by',tracks_by);
  205.             { form }
  206.             scope.find_vdu(scope_tracking,@dimensions);
  207.             scope.write_dimensions(@dimensions,left,top,'tracking',ini_file);
  208.             writebool('tracking','visible',visible);
  209.         end;
  210. end;
  211.  
  212.     { ------
  213.         events
  214.         ------ }
  215.  
  216. procedure tscope_tracking.FormShow(
  217.     Sender:TObject);
  218. begin
  219.     with dimensions do
  220.         begin
  221.             top:=form_top;
  222.             left:=form_left;
  223.         end;
  224. end;
  225.  
  226. procedure tscope_tracking.adjust;
  227. begin
  228.     with dimensions do
  229.         begin
  230.             form_top:=trunc(form_top/last_screen_height*current_height);
  231.             form_left:=trunc(form_left/last_screen_width*current_width);
  232.         end;
  233.     if visible then
  234.         show;
  235. end;
  236.  
  237. procedure tscope_tracking.check_visible_and_show_hide(
  238.     sender:tobject);
  239. begin
  240.     if visible then
  241.         hide_form
  242.     else
  243.         show_form;
  244.     scope.show_hide(sender,visible);
  245. end;
  246.  
  247. procedure tscope_tracking.hide_form;
  248. begin
  249.     with dimensions do
  250.         begin
  251.             form_top:=top;
  252.             form_left:=left;
  253.         end;
  254.     Visible:=false;
  255. end;
  256.  
  257. procedure tscope_tracking.show_form;
  258. begin
  259.     Visible:=true;
  260. end;
  261.  
  262. procedure Tscope_tracking.check_activate(
  263.     Sender: TObject);
  264. begin
  265.     scope.form_activate(scope_tracking,@dimensions);
  266. end;
  267.  
  268. procedure Tscope_tracking.decrease_tracking_buttonClick(
  269.     Sender: TObject);
  270. begin
  271.     if (scope_network.send_request_check('decrease_tracking')>=[exit_ok]) then
  272.         begin
  273.             tracking_rate:=tracking_rate-default_deviation;
  274.             tracking_edit.text:=floattostr(tracking_rate);
  275.         end;
  276. end;
  277.  
  278. procedure Tscope_tracking.increase_tracking_buttonClick(
  279.     Sender: TObject);
  280. begin
  281.     if (scope_network.send_request_check('increase_tracking')>=[exit_ok]) then
  282.         begin
  283.             tracking_rate:=tracking_rate+default_deviation;
  284.             tracking_edit.text:=floattostr(tracking_rate);
  285.         end;
  286. end;
  287.  
  288. procedure Tscope_tracking.lunar_tracking_buttonClick(
  289.     Sender: TObject);
  290. begin
  291.     scope_network.send_request_check('lunar_tracking');
  292.     tracking_rate:=default_lunar_tracking_rate;
  293.     tracking_edit.text:=floattostr(tracking_rate);
  294. end;
  295.  
  296. procedure Tscope_tracking.default_tracking_buttonClick(
  297.     Sender: TObject);
  298. begin
  299.     scope_network.send_request_check('default_tracking');
  300.     tracking_rate:=default_tracking_rate;
  301.     tracking_edit.text:=floattostr(tracking_rate);
  302. end;
  303.  
  304. procedure Tscope_tracking.tracking_editChange(
  305.     Sender: TObject);
  306. begin
  307.     tracking_edit.text:=floattostr(tracking_rate);
  308. end;
  309.  
  310. end.
  311.